www.gusucode.com > VC++ Windows错误信息查看器源代码-源码程序 > VC++ Windows错误信息查看器源代码-源码程序/code/ListDialog.cpp
// ListDialog.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "WinErrCodeViewer.h" #include "ListDialog.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CListDialog dialog CListDialog::CListDialog(CWnd* pParent /*=NULL*/) : CDialog(CListDialog::IDD, pParent) { //{{AFX_DATA_INIT(CListDialog) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CListDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CListDialog) DDX_Control(pDX, IDC_LIST, m_ctrlList); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CListDialog, CDialog) //{{AFX_MSG_MAP(CListDialog) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CListDialog message handlers BOOL CListDialog::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here int i; CString str1,str2,strTemp; LPVOID lpMsgBuf; HLOCAL hMsgBuf; OSVERSIONINFO OsVersionInfo; strTemp=""; m_ctrlList.InsertColumn(0,"Code And Message Descriptions",LVCFMT_LEFT,485,0); m_ctrlList.SetTextColor((COLORREF)0x00ff0000); //以下是版本的检测 OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO); GetVersionEx(&OsVersionInfo); //*********以下这个是98和ME的*************************** if(OsVersionInfo.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS) { m_ctrlList.SetItemCount(8000); hMsgBuf=LocalAlloc(LMEM_MOVEABLE|LMEM_ZEROINIT,1000); if(hMsgBuf==NULL) { MessageBox("内存分配失败!","错误",MB_ICONEXCLAMATION); exit(1); } lpMsgBuf=LocalLock(hMsgBuf); if(lpMsgBuf==NULL) { MessageBox("内存分配失败!","错误",MB_ICONEXCLAMATION); exit(1); } for(i=0;i<8000;i++) { SetLastError(i); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_FROM_SYSTEM| FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); str1=(LPCTSTR)lpMsgBuf; if(str1==strTemp) { continue; } str2.Format(_T("%-8d %s"),i,str1); m_ctrlList.InsertItem(i,(LPCTSTR)str2); strTemp=str1; } LocalUnlock(hMsgBuf); LocalFree(lpMsgBuf); UpdateData(FALSE); } //*********以下这个是NT和2000的*************************** else if(OsVersionInfo.dwPlatformId =VER_PLATFORM_WIN32_NT) { m_ctrlList.SetItemCount(10000); for(i=0;i<11111;i++) { SetLastError(i); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_FROM_SYSTEM| FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), // Default language (LPTSTR)&lpMsgBuf, 0, NULL); str1=(LPCTSTR)lpMsgBuf; if(str1=="") { continue; } str2.Format(_T("%-8d %s"),i,(LPCTSTR)str1); m_ctrlList.InsertItem(i,str2); } LocalFree(lpMsgBuf); UpdateData(FALSE); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }